package com.ssy.lingxi.report.dao.platformmanage;

import com.ssy.lingxi.report.model.bo.PlatformParameterManageBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 平台参数管理DAO
 * @author 伍将
 * @date 2020/12/14
 * @version 2.0.0
 */
@Service
public class PlatformParameterManageDAO {

    @Autowired
    @Qualifier("platformManageJdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    /**
     * 根据参数编码查询参数值
     * @return
     */
    public PlatformParameterManageBO getParameter(String code) {
        StringBuilder sql = new StringBuilder();
        sql.append(" select ")
                .append(" parameter_value as value")
                .append(" FROM ")
                .append(" man_platform_parameter_manage ")
                .append(" where state=1")  // 有效
                .append(" and code='" + code + "';");

        PlatformParameterManageBO result = null;
        List<PlatformParameterManageBO> resultLis = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<>(PlatformParameterManageBO.class));
        if (resultLis.size() > 0) {
            result = resultLis.stream().findFirst().orElse(null);
        }

        return result;
    }
}
